﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tools;
using 纺织贸易管理系统;
using 纺织贸易管理系统.设置窗体;

namespace 后整理管理系统.出库管理
{
    public partial class 架子出库确认 : Sunny.UI.UIForm
    {
        public List<StockTable> stocks { get; set; } = new List<StockTable>();

        public 架子出库确认()
        {
            InitializeComponent();
            CreateGrid.Create("库存报表", gridView1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Connect.dbcontext.BeginTran();
                foreach(int row in gridView1.GetSelectedRows())
                {
                    var stock = stocks.FirstOrDefault(x => x.ID == (int)gridView1.GetRowCellValue(row, "ID"));
                    RukuTableService.InsertRukuTable(stock);
                    Connect.dbcontext.Deleteable(stock).ExecuteCommand();
                }
                Connect.dbcontext.CommitTran();
                this.Close();
            }
            catch(Exception ex)
            {
                Connect.dbcontext.RollbackTran();
                ShowMessageBox.ShowErrorBox("发送了错误:" + ex.Message);
            }
        }

        private void 架子出库确认_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = stocks;
        }
    }
}
